package com.lottery.controller;

import com.lottery.entity.LotteryActivity;
import com.lottery.entity.LotteryWinner;
import com.lottery.service.LotteryService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/lottery")
@RequiredArgsConstructor
public class LotteryController {
    private final LotteryService lotteryService;
    
    /**
     * 查询进行中的活动
     */
    @GetMapping("/activities")
    public List<LotteryActivity> getOngoingActivities() {
        return lotteryService.getOngoingActivities();
    }
    
    /**
     * 参与抽奖
     */
    @PostMapping("/participate")
    public LotteryWinner participate(@RequestParam Integer userId,
                                   @RequestParam Integer activityId,
                                   @RequestHeader("X-Real-IP") String ipAddress,
                                   @RequestHeader("X-Device-ID") String deviceId) {
        return lotteryService.participate(userId, activityId, ipAddress, deviceId);
    }
    
    /**
     * 领取奖品
     */
    @PostMapping("/claim/{winnerId}")
    public Boolean claimPrize(@PathVariable Long winnerId) {
        return lotteryService.claimPrize(winnerId);
    }
} 